package cn.asiontang.utils;

import android.app.Application;

public final class TextUtils
{
    private static Application sContext;

    /**
     * 一般在自定义Application中的onCreate里初始化<br/>
     * 【不能在Application的构造函数里调用！】<br/>
     * 因为此时应用的String资源尚未初始化完毕，会报Null异常！
     */
    public static final void init(final Application app)
    {
        sContext = app;
    }

    public static final String getString(final int sqlResId)
    {
        return sContext.getString(sqlResId);
    }

    public static final String getString(final int resId, final Object... formatArgs)
    {
        return sContext.getString(resId, formatArgs);
    }

    public static final String[] getStringArray(final int resId)
    {
        return sContext.getResources().getStringArray(resId);
    }

    public static final boolean isEmpty(final CharSequence str)
    {
        return str == null || str.length() == 0;
    }

    public static final boolean isEmptyOrOnlyWhiteSpace(final CharSequence value)
    {
        return null == value//
                || value.length() == 0//
                || android.text.TextUtils.getTrimmedLength(value) == 0;
    }

    /**
     * 和 String.valueOf(Object) 区别就是value为Null时，返回字符串""，而不是"null"!
     */
    public static final String valueOfNoNull(final Object value)
    {
        return value != null ? value.toString() : "";
    }
}
